//
// Description: 5978. 统计追加字母可以获得的单词数
// Created by Loading on 2022/1/9.
//

#include <bits/stdc++.h>

using namespace std;

int wordCount(vector<string> &startWords, vector<string> &targetWords) {
    unordered_set<int> s;
    /* 状态压缩思想，将单词对应的二进制掩码存储 */
    for (auto &word : startWords) {
        int mask = 0;
        for (auto &c : word) {
            mask |= 1 << (c - 'a');
        }
        s.insert(mask);
    }

    int res = 0;
    for (auto &word : targetWords) {
        int mask = 0;
        for (auto &c : word) {
            mask |= 1 << (c - 'a');
        }
        // 按位置零，并查找哈希表
        for (auto &c : word) {
            if (s.count(mask ^ (1 << (c - 'a')))) {
                ++res;
                break;
            }
        }
    }

    return res;
}

int main() {
    vector<string> startWords = {"ant", "act", "tack"};
    vector<string> targetWords = {"tack", "act", "acti"};
    int res = wordCount(startWords, targetWords);
    cout << res << endl;

    return 0;
}
